﻿using Ldt.DataEngine.DataFlowParse.Model;
using LdtDataEngin.ModuleDetail.BaseModule;
using LdtJudge.DataEngine.DataBaseStores;
using System.Collections.Generic;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.AnalysisModule.TextformattingExtr
{
    /// <summary>
    /// 文本格式化提取模块
    /// 输入信息:文本格式化提取的配置信息===>DataContext.DataLayerSysStores
    /// 输出信息:文本格式化提取后的文本DataContext.DyData_Analysis.An_fengxicanshu.Juanzongneirong
    /// </summary>
    public class TextformattingAssemble : AssermBase
    {
        /// <summary>
        /// 模块配置
        /// </summary>
        private List<ConfigModel> moduleConfig = new List<ConfigModel>();

        public TextformattingAssemble(DataContext context,string moudleName)
        {
            dataContext = context;
            base.MoudleName = moudleName;
        }

        /// <summary>
        /// 开始提取
        /// </summary>
        public void Extrat()
        {
            var configModel = dataContext.DataLayerSys.GetConfigModel(MoudleName);
            XmlDocument document = new XmlDocument();
            document.LoadXml(configModel.ConfigContent);
            foreach (XmlNode item in document.FirstChild.ChildNodes)
            {
                ConfigModel stepConfig = new ConfigModel();
                stepConfig.ExecuteType = item.Attributes["executetype"]?.Value;
                stepConfig.FilePath = item.Attributes["executefile"]?.Value;
                moduleConfig.Add(stepConfig);
            }
            foreach (var item in moduleConfig)
            {
                if (item.ExecuteType == "reg")
                {
                    ExeConfig(item, MoudleName);
                }
                else if (item.ExecuteType == "dll")
                {
                    TextformattingDLL dllTextformat = new TextformattingDLL(dataContext);
                    dllTextformat.Extract(item.FilePath, MoudleName);
                }
                else if (item.ExecuteType == "xml")
                {
                }
            }
        }
    }
}
